package com.seecen.cywbackend.controller;

import com.seecen.cywbackend.pojo.vo.CommentDTO;
import com.seecen.cywbackend.service.CommentService;
import com.seecen.cywbackend.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comment")
public class CommentController {
    @Resource
    private CommentService commentService;

    // 获取评论列表
    @GetMapping("/list")
    public Result getComments(
            @RequestParam Integer dynamicId,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestHeader String uid) {
        Long userId = Long.parseLong(uid);
        return commentService.getComments(dynamicId, page, size,userId);
    }

    // 发表评论
    @PostMapping("/publish")
    public Result createComment(
            @RequestBody @Validated CommentDTO dto,
            @RequestHeader String uid) {
        Long userId = Long.parseLong(uid);
        return Result.ok(commentService.createComment(userId, dto));
    }
}
